package com.starblink.product.detail.dialog.review

import com.starblink.android.basic.adapter.BaseBindingVH
import com.starblink.android.basic.ext.visibleOrGone
import com.starblink.android.basic.extension.dp2px
import com.starblink.basic.ext.screenWidth
import com.starblink.basic.util.CommUtils
import com.starblink.product.R
import com.starblink.product.databinding.ItemProductReviewBinding
import com.starblink.rocketreserver.FetchSelectedProductReviewQuery

class ProductReviewHolder(
    binding: ItemProductReviewBinding,
    val listener: () -> Unit
) :
    BaseBindingVH<FetchSelectedProductReviewQuery.FetchSelectedProductReview, ItemProductReviewBinding>(
        binding = binding
    ) {

    override fun onBind(
        data: FetchSelectedProductReviewQuery.FetchSelectedProductReview,
        position: Int
    ) {

        val viewWidth: Int = screenWidth - 35f.dp2px()
        binding.tvTitle.initWidth(viewWidth)
        binding.tvTitle.maxLines = 1
        binding.tvTitle.setOriginalText(data.title ?: "")
        binding.tvTitle.setHasAnimation(false)
        binding.tvTitle.setCloseInNewLine(false)
        binding.tvTitle.setOpenSuffixColor(CommUtils.getColor(com.starblink.basic.style.R.color.sk_gray300))
        binding.tvTitle.setCloseSuffixColor(CommUtils.getColor(com.starblink.basic.style.R.color.sk_gray300))

        binding.tvComment.initWidth(viewWidth)
        binding.tvComment.maxLines = 3
        binding.tvComment.setOriginalText(data.detail ?: "")
        binding.tvComment.setHasAnimation(false)
        binding.tvComment.setCloseInNewLine(false)
        binding.tvComment.setOpenSuffixColor(CommUtils.getColor(com.starblink.basic.style.R.color.sk_gray300))
        binding.tvComment.setCloseSuffixColor(CommUtils.getColor(com.starblink.basic.style.R.color.sk_gray300))
        val score: Double = data.score ?: 0.0
        binding.llScore.visibleOrGone(score >= 4) {
            binding.ivScore5.setImageResource(if (score > 4.5) R.mipmap.icon_good_score else if (score > 4) R.mipmap.icon_good_score_half else R.mipmap.icon_good_score_empty)
        }
    }

}